﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kiel.Pdf
{
	/// <summary>
	/// Represents a PDF Indirect Object.
	/// </summary>
	class PdfIndirectObject : IPdfObject
	{
		public PdfIndirectObject(int objectNumber, int generationNumber)
		{
			this.ObjectNumber = objectNumber;
			this.GenerationNumber = generationNumber;
		}

		public int GenerationNumber { get; private set; }

		public int ObjectNumber { get; private set; }

		public IPdfObject Value { get; set; }

		/// <summary>
		/// Creates a reference to this indirect object reference.
		/// </summary>
		/// <returns></returns>
		public PdfIndirectObjectReference CreateReference()
		{
			return new PdfIndirectObjectReference(this.ObjectNumber, this.GenerationNumber);
		}

		public override string ToString()
		{
			StringBuilder text = new StringBuilder();
			text.AppendFormat("{0} {1} obj", this.ObjectNumber, this.GenerationNumber);
			text.AppendLine();
			text.AppendLine(this.Value.ToString());
			text.AppendLine("endobj");
			return text.ToString();
		}
	}
}
